package com.apobates.jforum2.troll.threads.biz.impl.api;

import com.apobates.jforum2.troll.regular.ForumActionEnum;
import com.apobates.jforum2.troll.threads.ThreadsFeignClientConfig;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 话题内部服务客户端
 * @author xiaofanku
 * @since 20210413
 */
@Component
@FeignClient(value="TROLL-GATEWAY", configuration = ThreadsFeignClientConfig.class)
@RequestMapping("/")
public interface TopicFeignServiceApi {
    @PutMapping(value="/board/{id}/stats/balance", consumes="application/x-www-form-urlencoded")
    ResponseEntity<String> balanceTopic(@RequestParam("target")long targetBoardId, @PathVariable("id")long boardId);
    // 话题移动:
    // 平衡版块统计中的话题数量
    @PutMapping(value="/board/{id}/stats/balance/posts", consumes="application/x-www-form-urlencoded")
    ResponseEntity<String> balanceTopicPosts(@RequestParam("target")long targetBoardId, @PathVariable("id")long boardId, @RequestParam("replies")long replies);
    // 话题发布:
    // 更新版块统计的最近话题
    @PutMapping(value="/board/{id}/stats/update", consumes="application/x-www-form-urlencoded")
    ResponseEntity<String> updateStatsRecentTopic(
            @PathVariable("id")long boardId,
            @RequestParam("topic")long recentTopicId,
            @RequestParam("title")String recentTopicTitle,
            @RequestParam("member")long recentTopicMemberId,
            @RequestParam("nickname")String recentTopicMemberNickname);
    // 话题移动:
    // 更新回复所属的版块
    @PutMapping(value="/posts/reset/topic/{id}", consumes="application/x-www-form-urlencoded")
    ResponseEntity<String> balanceReplyTopic(@RequestParam("target")long targetBoardId, @RequestParam("targetBoardGroup")int targetBoardGroupId, @PathVariable("id")long topicId);
    // 创建话题:
    // 插入话题内容
    @PutMapping(value="/posts/entry/topic/{id}", consumes="application/x-www-form-urlencoded")
    ResponseEntity<String> entryTopicContent(
            @PathVariable("id")long topicId,
            @RequestParam("content")String topicContent, 
            @RequestParam("board")long boardId, 
            @RequestParam("boardgroup")int boardGroupId, 
            @RequestParam("member") long memberId,
            @RequestParam("nickname") String memberNickname,
            @RequestParam("token") String token,
            @RequestParam("ip") String ipAddr);
    // 编辑话题:
    // 更新话题内容
    @PutMapping(value="/posts/modify/topic/{id}", consumes="application/x-www-form-urlencoded")
    ResponseEntity<String> modifyTopicContent(
            @PathVariable("id")long topicId,
            @RequestParam("content")String topicContent,
            @RequestParam("member") long memberId,
            @RequestParam("nickname") String memberNickname);
    
    //:/logs
    @GetMapping("/logs/topic/liked")
    boolean isLikedTopic(@RequestParam("topic")long topicId, @RequestParam("member")long memberId);
    
    @GetMapping("/logs/topic/favorited")
    boolean isFavoritedTopic(@RequestParam("topic")long topicId, @RequestParam("member")long memberId);
    
    @GetMapping("/logs/topic/action/member")
    long getActionTopic(@RequestParam("topic")long topicId, @RequestParam("member")long memberId, @RequestParam("action")ForumActionEnum action);
    //从话题点赞/取消点赞中脱离出来 | 从话题收藏/取消收藏中脱离出来
    //为下次取消点赞/点赞清路      | 为下次取消收藏/收藏清路
    @PostMapping(value="/logs/topic/action/delete", consumes="application/x-www-form-urlencoded")
    boolean removeActionTopic(@RequestParam("topic")long topicId, @RequestParam("member")long memberId, @RequestParam("action")ForumActionEnum action);
}